<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

function ChkDate($date) {
//
    $parts = array();
    preg_match("/^([0-9]{2})\/([0-9]{2})\/([0-9]{4})$/", $date, $parts);
    //print "<br>";
    //var_dump($parts);
    //){
    //check weather the date is valid of not        

    if (checkdate($parts[2], $parts[1], $parts[3])) {
        return true;
    } else {
        return false;
    }
}

function NNR_Cases_to_claims(&$MapRec, &$Data, &$Pos, &$_SESSION['Work'], &$UE_Opts) {
    //
    $TableName = $MapRec['TableName'];
    $csvCol = explode(",", $MapRec['csvCol']);
    $MapTo = explode(",", $MapRec['MapTo']);
    $TableCol = explode(",", $MapRec['TableCol']);
    $UserExit = explode(",", $MapRec['UserExits']);
    $ColType = explode(",", $MapRec['DataType']);
    $cCount = count($TableCol);
    $csvCount = count($csvCol);
    $DoMap = array();
    for ($c = 0; $c < $csvCount; $c++) {
        //print $MapTo[$c] . ", ";
        if ($MapTo[$c] <> "") {
            $DoMap[$MapTo[$c]] = $c;
        }
    }
    $Exit = $UE_Opts['Exit'];
    $Trace = $UE_Opts['Trace'];
    $Column = $TableCol[$Pos];
    if ($DoMap[$Pos]) {
        $Val = $Data[$DoMap[$Pos]];
    } else {
        $Val = "";
    }
    if ($Trace) {
        print " - Pos=" . $Pos . " Column=" . $Column . " Val=" . $Val . " Exit=" . $Exit;
    }
    switch ($Exit) {
        Case "A":
            //at very start
            break;
        Case "E":
            //before field entry/import
            switch ($Column) {
                case "StatusDate":
                    $chk = ChkDate($Val);
                    if (!$chk) {
                        $Val = "";
                    }
                    break;
                case "NextActDate":
                    $chk = ChkDate($Val);
                    if (!$chk) {
                        $Val = "";
                    }
                    break;
                default:
                    $Val = "";
                    break;
            }
            break;
        Case "F":
            //after field entry/import
            switch ($Column) {
                case "Division":
                    //print "case Division";
                    $Val = "T";
                    break;
                case "ClientID":
                    $Val = $_SESSION['Work']['ClientID'];
                    //print $Val;
                    break;
                case "LenderID":
                    $Val = $_SESSION['Work']['LenderID'];
                    break;
                default:
                    $Val = "";
                    break;
            }
            break;
        default:
            //do nothing!
            break;
    }
//
    return $Val;
}

?>